Conversation
…elations tests accordingly
Kf/model relations tests
…increase_inventory and set_check_in
removing inventory adjustments from check-in action
Kf/simplecov
Kf/movie validation tests
Video StoreWhat We're Looking For
|
| def index | ||
| customers = Customer.all | ||
| render json: customers.as_json(only: [:id, :name, :registered_at, :address, :city, :state, :postal_code, :phone], methods: :movies_checked_out_count), status: :ok | ||
| end |
There was a problem hiding this comment.
I would probably break like 5 across multiple lines for readability.
| if movie.save | ||
| render json: { id: movie.id }, status: :ok | ||
| else | ||
| render json: { errors: movie.errors.messages }, status: :bad_request |
There was a problem hiding this comment.
The error response on line 22 doesn't match the one in show above (line 12). That one has ok and messages as the keys, but this one sends errors. Best practice is to pick one error reporting format and stick with it.
| customer = Customer.find_by(id: params[:customer_id]) | ||
| error = "Customer not found" if customer == nil | ||
|
|
||
| movie = Movie.find_by(id: params[:movie_id]) |
There was a problem hiding this comment.
You have a bunch of business logic here! Would it be possible to encapsulate this in a model method? Something like
Rental.check_out(customer_id, movie_id)
might be a good interface. That would make this logic easier to test as well.
|
|
||
| def movies_checked_out_count | ||
| return Rental.where(check_in_date: nil).count | ||
| end |
There was a problem hiding this comment.
I love that you made Customer#movies_checked_out_count and Movie#available_inventory methods instead of storing them in the database. That way there's no way to forget to update these values.
Video Store API
Congratulations! You're submitting your assignment!
If you didn't get to the functionality the question is asking about, reply with what you would have done if you had completed it.
Comprehension Questions
POST /rentals/check-inendpoint? What does the time complexity depend on? Explain your reasoning.